var vm =  new Vue({
		el:"#app",
		data:{
			list:[
				//{id:1,username:'wangbo',password:'fdsfsdf',name:'dfds',email:'dfs',phone:'5555555',registerTime:new Date(),state:1,role:1},
					//{id:1,adminName:'rootroot',password:'1314520zx',email:'2574357303@qq.com',registerTime:new Date(),state:1,createById:1},
					//{id:2,adminName:'rootroot',password:'1314520zx',email:'2574357303@qq.com',registerTime:new Date(),state:1,createById:1}
					],
			index: -1,
			keys: '',
			head:[
					['id','username','password','name','email','phone','registerTime','state','role'],
					['id','adminName','password','email','registerTime','state','createById'],
					['id','dirId','fileName','fileSize','fileType','fileUploadTime','fileStatus'],
					['id','dirName','dirParentId','userId','dirPath']
					],
			index:0,
			modifyObj:{},
			objType:1,
			newObj:{},
			adId:0,
			admin:[]
		},
		methods:{
			
			getData: function (){
				var _this = this;
				//实体类型
				var type = this.objType;
				$.ajax({
		             type: "POST",
		             url: ___Path +  "/user/query.json",
		             dataType: "json",
		             data: JSON.stringify({'info':{'objCode':type}}),
		             contentType: "application/json",
		             success: function(data){
		            	_this.list = data.data.list;
	                     },
	                 error: function(e){
	                 	alert("查询失败");
	                 	console.log(e);
	                 }
		         });
			},
			
			getType: function(type){
				var _this = this;
				_this.objType = type;
				console.log(this.objType)
				this.getData();
			},
			
			search: function(){
				let t = this
				let list = this.list;
				let head = this.head;
				// 第二次渲染时去除上一的标签
				let reg = /<\/?.+?\/?>/g;
				for(let i = 0; i < list.length; i++){
					let flag = false;
					for(let ii = 0; ii < head[t.objType-1].length; ii++){
						if(list[i][head[t.objType-1][ii]] == null) {
							continue
						}
						list[i][head[t.objType-1][ii]] = list[i][head[t.objType-1][ii]].toString().replace(reg,'');
						if((list[i][head[t.objType-1][ii]]).toString().indexOf(t.keys) != -1){
							flag = true;
							list[i][head[t.objType-1][ii]] = list[i][head[t.objType-1][ii]].toString().replace(eval("/"+t.keys+"/g"),'<font color=\'red\'><b>' + this.keys + '</b></font>');
						}
					}
					if(flag){
					}
				}
				
				// 对条件显示数组排序
				
				
				this.$nextTick(function(){
					//整理表格
					let tableObj1 = document.getElementsByClassName("tableObj1");
					let tableObj2 = document.getElementsByClassName("tableObj2");
					if(tableObj1 != null){
						for(let i=0; i<tableObj2.length; i++){
							tableObj2[i].style.width = tableObj1[i].offsetWidth + 'px';	
						}
					}
				})
				
				return list
			},
			
			modify: function (){
				var _this = this;
				//实体类型
				var type = this.objType;
				//修改表单值
				var obj = this.modifyObj;
				var str;
				switch(type){
				case 1:{
					str = {'info':{'objCode':type},'obj':{'id':Number(obj.id),'username':obj.username,'password':obj.password,'name':obj.name,'phone':obj.phone,'email':obj.email,'state':Number(obj.state),'role':Number(obj.role)}};
					break;
					}
				case 2:{
					str = {'info':{'objCode':type},'obj':{'id':Number(obj.id),'adminName':obj.adminName,'password':obj.password,'email':obj.email,'state':Number(obj.state),'createById':Number(obj.createById)}};
					break;
					}
				case 3:{
					str = {'info':{'objCode':type},'obj':{'id':Number(obj.id),'dirId':Number(obj.dirId),'fileType':obj.fileType,'fileStatus':Number(obj.fileStatus)}};
					break;
					}
				case 4:{
					str = {'info':{'objCode':type},'obj':{'id':Number(obj.id),'dirName':obj.dirName,'dirParentId':Number(obj.dirParentId),'userId':Number(obj.userId),'dirPath':obj.dirPath}};
					break;
					}
				}
				
				$.ajax({
		             type: "POST",
		             url: ___Path +  "/user/update.json",
		             data: JSON.stringify(str),
		             contentType: "application/json",
		             dataType: "json",
		             success: function(data){
		            	 if(data.data.count > 0){
			            	//关闭模态框
							$('#exampleModa1').modal('hide');
		            		 alert("修改成功");
		            		 _this.getData();
		            	 }else{
		            	 	alert("修改失败");
		            	 }
	                 },
	                 error: function(error){
	                	 alert("修改失败");
	                 }
		         });
			},
			
			delect: function(id,i){//需要删除的id,索引
				//实体类型
				var _this = this;
				var type = this.objType;

				$.ajax({
		             type: "POST",
		             url: ___Path +  "/user/remove.json",
		             data: JSON.stringify({'info':{'objCode':type},'obj':{'ids':[id]}}),
		             contentType: "application/json",
		             dataType: "json",
		             success: function(data){
		            	 if(data.data.count > 0){
			            	//删除数据
							_this.list.splice(i,1);
		            		 alert("删除成功");
		            	 }else{
		            	 	alert("删除失败");
		            	 }
	                 },
	                 error: function(error){
	                	 alert("删除失败");
	                 }
		         });
				
			},
			
			add: function(){
				var _this = this;
				//实体类型
				var type = this.objType;
				//新增数据
				var obj = this.newObj;
				//渲染数据
				//_this.list.push(this.newObj);
				
				var str;
				switch(type){
				case 1:{
					str = {'info':{'objCode':type},'obj':{'username':obj.username,'password':obj.password,'name':obj.name,'phone':obj.phone,'email':obj.email,'state':Number(obj.state),'role':Number(obj.role)}};
					break;
					}
				case 2:{
					str = {'info':{'objCode':type},'obj':{'adminName':obj.adminName,'password':obj.password,'email':obj.email,'state':Number(obj.state),'createById':Number(obj.createById)}};
					break;
					}
				case 3:{
					str = {'info':{'objCode':type},'obj':{'dirId':Number(obj.dirId),'fileType':obj.fileType,'fileStatus':Number(obj.fileStatus)}};
					break;
					}
				case 4:{
					str = {'info':{'objCode':type},'obj':{'dirName':obj.dirName,'dirParentId':Number(obj.dirParentId),'userId':Number(obj.userId),'dirPath':obj.dirPath}};
					break;
					}
				}
				
				$.ajax({
		             type: "POST",
		             url: ___Path +  "/user/add.json",
		             data: JSON.stringify(str),
		             contentType: "application/json",
		             dataType: "json",
		             success: function(data){
		            	 if(data.data.count > 0){
		            	 	//渲染数据
		            		 $('#exampleModa2').modal('hide');
		            		 alert("添加成功");
		            		 _this.getData();
		            	 }else{
		            	 	alert("添加失败");
		            	 }
	                 },
	                 error: function(error){
	                	 alert("添加失败");
	                 }
		         });
		         
		         //关闭模态框
			},
			
			keepTable: function(){
				//整理表格
				var tableObj1 = document.getElementsByClassName("tableObj1");
				var tableObj2 = document.getElementsByClassName("tableObj2");
				if(tableObj1 != null){
					for(var i=0; i<tableObj2.length; i++){
						tableObj2[i].style.width = tableObj1[i].offsetWidth + 'px';	
					}
				}
				
			},
			
			
			
			setCookie: function (cname, cvalue, exdays) {
		        var d = new Date();
		        d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
		        var expires = "expires=" + d.toUTCString();
		        console.info(cname + "=" + cvalue + "; " + expires);
		        document.cookie = cname + "=" + cvalue + "; " + expires;
		        console.info(document.cookie);
			},
			
			getCookie: function (cname) {
		        var name = cname + "=";
		        var ca = document.cookie.split(';');
		        console.log("获取cookie,现在循环")
		        for (var i = 0; i < ca.length; i++) {
		          var c = ca[i];
		          console.log(c)
		          while (c.charAt(0) == ' ') c = c.substring(1);
		          if (c.indexOf(name) != -1){
		            return c.substring(name.length, c.length);
		          }
		        }
		        return "";
      		},
      		
      		 clearCookie: function (username) {
        		this.setCookie(username, "", -1);
      		},
      		
      		
		    checkCookie: function (key) {
		        var user = this.getCookie(key);
		        if (user == "" || user == null) {
					alert("请登录！")
					window.location.href = projectName + "/adminLogin.html";
		    	}else{
		    		this.adId = user;
		    		this.UserID = user-1+1;
		    		this.getData();
		    		this.getAdminData();
		    	}
		    },
		    
		    logout: function (){
		    	this.clearCookie("admin");
		    	this.checkCookie("admin");
		    },
		    
		    getAdminData: function(){
		    	var _this = this;
				$.ajax({
		             type: "POST",
		             url: ___Path +  "/user/query.json",
		             dataType: "json",
		             data: JSON.stringify({'info':{'objCode':2},'obj':{'id':Number(_this.adId)}}),
		             contentType: "application/json",
		             success: function(data){
		            	_this.admin = data.data.list;
	                     },
	                 error: function(e){
	                 	alert("管理员信息查询失败");
	                 	console.log(e);
	                 }
		         });
		    }
	}
});
vm.checkCookie("admin");